package com.hckjsec.common.utils;

import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.sms.v20190711.SmsClient;
import com.tencentcloudapi.sms.v20190711.models.SendSmsRequest;
import com.tencentcloudapi.sms.v20190711.models.SendSmsResponse;

import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;

public class TxSmsUtil {
    private final static String endpoint = "sms.tencentcloudapi.com";
    public static Map<String,String> stateMbHt = new Hashtable<String,String>();
    static {
        if(stateMbHt.size()==0){
            stateMbHt.put("1","1171536");//订单通知
            stateMbHt.put("2","1171537");//订单变更
            stateMbHt.put("3","1095918");//审核成功通知
            stateMbHt.put("4","1095927");//审核失败通知
            stateMbHt.put("5","1095929");//材料补充
            stateMbHt.put("6","1030429");//预约成功通知
            stateMbHt.put("7","1030627");//预约失败通知
            stateMbHt.put("8","1048411");//视频通知
            stateMbHt.put("9","1167825");//网站验证码
            stateMbHt.put("10","1171541");//咨询回复通知
            stateMbHt.put("11","1227414");//公法小程序咨询订单通知工作人员
            stateMbHt.put("12","1227415");//公法小程序预约订单通知工作人员
            stateMbHt.put("13","1228310");//公法小程序政务服务订单通知工作人员
            stateMbHt.put("14","1199226");//公法小程序咨询回复通知
            stateMbHt.put("15","1206962");//容城县公共法律服务预约
        }
    }
    public static void sendSms(Hashtable<String, String> config, SendSmsRequest sendSms, String secretId, String secretKey) {
        SendSmsResponse resp = null;
        try {
            Credential cred = new Credential(secretId,secretKey);
            HttpProfile httpProfile = new HttpProfile();
            httpProfile.setEndpoint(endpoint);
            ClientProfile clientProfile = new ClientProfile();
            clientProfile.setHttpProfile(httpProfile);
            SmsClient client = new SmsClient(cred, "", clientProfile);
            resp = client.SendSms(sendSms);
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("短信发送==>"+SendSmsResponse.toJsonString(resp));
    }

    //数据组装
    public static void smsData(String secretId,String secretKey,String SmsSdkAppid,String sign,List<String> phonelist,String lx, String one,String two,String three){
        if(!"".equals(StringUtils.isHcNull(sign, "")) && phonelist.size()>0){
            String[] phoneNumberSet1=phonelist.toArray(new String[phonelist.size()]);
            SendSmsRequest reqSms = new SendSmsRequest();
            reqSms.setPhoneNumberSet(phoneNumberSet1);
            List<String> ParamSet1List = new ArrayList<String>();
            if(!"".equals(one)){
                ParamSet1List.add(one);
            }
            if(!"".equals(two)){
                ParamSet1List.add(two);
            }
            if(!"".equals(three)){
                ParamSet1List.add(three);
            }
            String[] templateParamSet1 = ParamSet1List.toArray(new String[ParamSet1List.size()]);
            reqSms.setTemplateParamSet(templateParamSet1);
            reqSms.setTemplateID(stateMbHt.get(lx));
            reqSms.setSmsSdkAppid(SmsSdkAppid);
            reqSms.setSign(sign);
            sendSms(null, reqSms, secretId, secretKey);
        }



    }







}
